package org.example.domain.strategy.service.rule.tree.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.domain.strategy.model.vo.RuleLogicCheckTypeVO;
import org.example.domain.strategy.service.rule.tree.ILogicTreeNode;
import org.example.domain.strategy.service.rule.tree.factory.DefaultTreeFactory;
import org.example.types.common.Constants;
import org.springframework.stereotype.Component;

/**
 * 1- 兜底奖品节点（实现类）
 */
@Slf4j
@Component("rule_luck_award")
public class RuleLuckAwardLogicTreeNode implements ILogicTreeNode {
    @Override
    public DefaultTreeFactory.TreeActionEntity logic(String userId, Long strategyId, Integer awardId, String ruleValue) {


        log.info("规则树过滤---兜底奖品");
        String[] split = ruleValue.split(Constants.COLON);

        if (split.length == 0) {
            throw new RuntimeException("规则树过滤-兜底奖品参数异常");
        }

        Integer luckyAward = Integer.valueOf(split[0]);
        String awardConfig = split.length > 1 ? split[1] : "";

        log.info("规则树过滤-兜底奖品-{}", luckyAward);
        return DefaultTreeFactory.TreeActionEntity.builder()
                .ruleLogicCheckType(RuleLogicCheckTypeVO.TAKE_OVER)
                .strategyAwardData(DefaultTreeFactory.StrategyAwardData.builder()
                        .awardId(awardId)
                        .awardRuleValue(awardConfig)
                        .build())
                .build();
    }
}
